﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;


public static class Extension  {

    /// <summary>
    /// 获取grid下的所有自物体
    /// </summary>
    /// <param name="grid"></param>
    /// <returns></returns>
    public static List<Transform> GetChildList(this GridLayoutGroup grid, bool hideObjInclude = false)
    {

        List<Transform> childs = new List<Transform>();
        foreach (Transform child in grid.transform)
        {
            if (hideObjInclude)
            {
                childs.Add(child);
            }
            else
            {
                if (child.gameObject.activeInHierarchy)
                    childs.Add(child);
            }
            
        }

        return childs;

    }

    /// <summary>
    /// 删除grid下的指定的物体
    /// </summary>
    /// <param name="grid"></param>
    /// <returns></returns>
    public static bool RemoveChild(this GridLayoutGroup grid,Transform target)
    {

        List<Transform> childList = grid.GetChildList(true);
        bool isRemoved = false;
        for (int i = 0; i < childList.Count; i++)
        {
            if (childList[i] == target)
            {
                childList.Remove(childList[i]);
                isRemoved = true;
            }
               
        }

        return isRemoved;

    }

    /// <summary>
    /// 重新刷新grid下的自物体
    /// </summary>
    /// <param name="grid"></param>
    public static void ResetPosition(this GridLayoutGroup grid)
    {

    }

}
